<?php

namespace App\Observers;

use App\Models\Product;
use App\Services\AddProductCloud\AddProductCloud;


class ProductObserver
{
	public function saved(Product $product)
	{
		$product->syncAttribute();
		
		if ($product->is_sale) {
			$product->addToCache();
			/*app(AddProductCloud::class, [
			    'product' => $product
		    ])->apply();*/
		} else {
			$product->delFromCache();
		}
	}
	
    public function deleting(Product $product)
    {
    	
       /* if (has_child($product, 'skus')) {
        	abort(403, '检测到对应 SKU');
        }
        if (has_child($product, 'slides')) {
	        abort(403, '检测到对应轮播图');
        }
        if (has_child($product, 'images')) {
        	abort(403, '检测到对应详情图');
        }
        if (has_child($product, 'orderItems')) {
        	abort(403, '检测到对应订单明细');
        }
        if (has_child($product, 'comments')) {
        	abort(403, '检测到对应商品评论');
        }*/
    }
    
    public function deleted(Product $product)
    {
	    $product->delFromCache();
    }
}
